;
(function() {
  new Vue({
    el: '#preview-list',
    data: {
      data: {},
      isImage: ['.jpg', '.jpeg', '.gif', '.png', '.bmp'],
      title: unescape(hlUrlUtil.GetQueryString('title'))
    },
    methods: {
      getinfo() {
        hlhttp.get({
          url: 'portal/publishing',
          data: {
            portal_article_id: hlUrlUtil.GetQueryString('portalArticleId')
          },
          success: (data) => {
            $('.html-preview').html(data.content)
            this.data = {
              title: data.title,
              memo: data.memo,
              files: []
            }
            data.attachmentsName.split(',').map((item, index) => {
              let type = item.substr(item.lastIndexOf('.'))
              if (this.isImage.indexOf(type) > -1) {
                this.data.files.push({
                  name: item,
                  url: data.attachmentsUrl.split(',')[index],
                  type: 'pic'
                })
              }
              if (this.isImage.indexOf(type) == -1) {
                this.data.files.push({
                  name: item,
                  url: data.attachmentsUrl.split(',')[index],
                  type: 'file'
                })
              }
            })
          }
        })
      },
      back() {
        hlUrlUtil.goTo('cEnd', {
          ddtab: true
        }, false)
        window.location.reload()
      }
    },
    created() {
      if (!hlUrlUtil.GetQueryString('clear')) {
        this.data = JSON.parse(window.sessionStorage.getItem('previewInfo'))
      }
    },
    mounted() {
      if (!hlUrlUtil.GetQueryString('clear')) {
        $('.html-preview').html(this.data.content)
      }
      if (hlUrlUtil.GetQueryString('portalArticleId')) {
        this.getinfo()
      }
    }
  })
}())
